//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类;

public class demo_1572 {
    public demo_1572() {
    }

    public static void main(String[] args) {
        int[][] mat = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        System.out.println(diagonalSum(mat));
    }

    public static int diagonalSum(int[][] mat) {
        if (mat.length == 1) {
            return mat[0][0];
        } else {
            int sum = 0;

            for(int i = 0; i < mat.length; ++i) {
                sum += mat[i][i];
                sum += mat[i][mat.length - 1 - i];
            }

            if (mat.length % 2 == 1) {
                int index = mat.length / 2;
                sum -= mat[index][index];
            }

            return sum;
        }
    }
}
